package cn.gson.crmdemo.model.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.crmdemo.model.dao.FkfpDao;
import cn.gson.crmdemo.model.mapper.FkfpMapper;
import cn.gson.crmdemo.model.pojo.PaymentInvoice;
import cn.gson.crmdemo.model.pojo.Purchase;
import cn.gson.crmdemo.model.pojo.Supplier;
import cn.gson.crmdemo.model.vo.FkkpjlVo;

@Service
@Transactional(rollbackFor=Exception.class)
public class FkfpService {
	@Autowired
	FkfpMapper fm;
	@Autowired
	FkfpDao fdao;
	
	
	public JSONArray fkfp(String piDate,String piPhone,Integer piYnpay){
		return fm.selectfkfp(piDate,piPhone,piYnpay);
	}
	
	public void addfkfp(FkkpjlVo fo) {
		int i=0;
		String st;
		PaymentInvoice pe=new PaymentInvoice();
		Purchase ps=new Purchase();
		ps.setPurchaseId(fo.getPurchaseId());
		pe.setPurchase(ps);
		Supplier sr=new Supplier();
		sr.setGysId(fo.getGysId());
		pe.setSupplier(sr);
		pe.setPiAbstract(fo.getPiAbstract());
		pe.setPiDate(fo.getPiDate());
		pe.setPiEmpName(fo.getPiEmpName());
		pe.setPiMoney(fo.getPiMoney());
		pe.setPiPhone(fo.getPiPhone());
		pe.setPiType(fo.getPiType());
		st=fo.getPiYnpay();
		if(st.equals("现金")) {
			i=1;
		}else if(st.equals("微信")){
			i=2;
		}else if(st.equals("支付宝")) {
			i=3;
		}else if(st.equals("银联")) {
			i=4;
		}
			pe.setPiPhone(fo.getPiPhone());
			pe.setPiYnpay(i);
		fdao.save(pe);
	}
	//发票查询
	public JSONArray selectfph(String fph) {
		return fm.selectfph(fph);
	}
	//查询日期
	public JSONArray selectsj(String rq) {
		return fm.selectsj(rq);
	}
	//查询付款方式
	public JSONArray selectfs(Integer q) {
		return fm.selectfs(q);
	}

}
